package com.net.xpay.sync.client;

import com.alibaba.otter.canal.protocol.CanalEntry;
import com.net.xpay.sync.NameUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;


@Slf4j
public class CanalBeanHelper {

    public static String convertToBeanJson(List<CanalEntry.Column> columnList) {
        if (CollectionUtils.isEmpty(columnList)) {
            return "{}";
        }
        StringBuilder beanJsonBuilder = new StringBuilder();
        for (CanalEntry.Column column : columnList) {
            beanJsonBuilder.append("\"").append(NameUtils.underlineToCamel(column.getName())).append("\":").append("\"").append(column.getValue()).append("\",");
        }
        return  "{" + beanJsonBuilder.toString().substring(0, beanJsonBuilder.length() - 1) + "}";
    }

}
